package com.xjy.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xjy.common.core.mybatisplus.core.ServicePlusImpl;
import com.xjy.common.core.page.PagePlus;
import com.xjy.common.core.page.TableDataInfo;
import com.xjy.common.utils.PageUtils;
import com.xjy.system.domain.ReportExpendBudget;
import com.xjy.system.domain.bo.ReportExpendBudgetQueryBo;
import com.xjy.system.domain.vo.ReportExpendBudgetVo;
import com.xjy.system.mapper.ReportExpendBudgetMapper;
import com.xjy.system.service.IReportExpendBudgetService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 报销科目汇总Service业务层处理
 *
 * @author mlb
 * @date 2022-03-20
 */
@Service
public class ReportExpendBudgetServiceImpl extends ServicePlusImpl<ReportExpendBudgetMapper, ReportExpendBudget> implements IReportExpendBudgetService {

    @Override
    public ReportExpendBudgetVo queryById(Long projId){
        return getVoById(projId, ReportExpendBudgetVo.class);
    }

    @Override
    public TableDataInfo<ReportExpendBudgetVo> queryPageList(ReportExpendBudgetQueryBo bo) {
        PagePlus<ReportExpendBudget, ReportExpendBudgetVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo), ReportExpendBudgetVo.class);
        return PageUtils.buildDataInfo(result);
    }

    @Override
    public List<ReportExpendBudgetVo> queryList(ReportExpendBudgetQueryBo bo) {
        return listVo(buildQueryWrapper(bo), ReportExpendBudgetVo.class);
    }

    private LambdaQueryWrapper<ReportExpendBudget> buildQueryWrapper(ReportExpendBudgetQueryBo bo) {
		Map<String, Object> params = bo.getParams();
		LambdaQueryWrapper<ReportExpendBudget> lqw = Wrappers.lambdaQuery();
		lqw.like(StrUtil.isNotBlank(bo.getName()), ReportExpendBudget::getName, bo.getName());
		lqw.like(StrUtil.isNotBlank(bo.getSubjectName()), ReportExpendBudget::getSubjectName, bo.getSubjectName());
		lqw.eq(StrUtil.isNotBlank(bo.getLevel()), ReportExpendBudget::getLevel, bo.getLevel());
		lqw.between(params.get("beginMonth") != null && params.get("endMonth") != null,
			ReportExpendBudget::getMonth ,params.get("beginMonth"), params.get("endMonth"));
		return lqw;
    }


}
